package cn.com.xf.dao.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import cn.com.xf.dao.TblOaAuthUserDAO;
import cn.com.xf.dao.support.XFSqlMapClientDaoSupport;
import cn.com.xf.domain.TblOaAuthUser;

@Repository
public class TblOaAuthUserDAOImpl extends XFSqlMapClientDaoSupport implements TblOaAuthUserDAO {

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	public TblOaAuthUserDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	@Override
	public int deleteByPrimaryKey(BigDecimal bizId) {
		TblOaAuthUser key = new TblOaAuthUser();
		key.setBizId(bizId);
		int rows = getSqlMapClientTemplate().delete("TBL_OA_AUTH_USER.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	@Override
	public Integer insert(TblOaAuthUser record) {
		return (Integer) getSqlMapClientTemplate().insert("TBL_OA_AUTH_USER.ibatorgenerated_insert", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	@Override
	public void insertSelective(TblOaAuthUser record) {
		getSqlMapClientTemplate().insert("TBL_OA_AUTH_USER.ibatorgenerated_insertSelective", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	@Override
	public TblOaAuthUser selectByPrimaryKey(BigDecimal bizId) {
		TblOaAuthUser key = new TblOaAuthUser();
		key.setBizId(bizId);
		TblOaAuthUser record = (TblOaAuthUser) getSqlMapClientTemplate().queryForObject(
				"TBL_OA_AUTH_USER.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	@Override
	public int updateByPrimaryKeySelective(TblOaAuthUser record) {
		int rows = getSqlMapClientTemplate().update("TBL_OA_AUTH_USER.ibatorgenerated_updateByPrimaryKeySelective",
				record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_USER
	 * 
	 * @ibatorgenerated Mon Jun 15 10:38:08 GMT+08:00 2015
	 */
	@Override
	public int updateByPrimaryKey(TblOaAuthUser record) {
		int rows = getSqlMapClientTemplate().update("TBL_OA_AUTH_USER.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	@Override
	public List<TblOaAuthUser> selectRoleByUserNames(List<String> userNameList) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userNameList", userNameList);
		@SuppressWarnings("unchecked")
		List<TblOaAuthUser> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_USER.ibatorgenerated_selectRolesByUserIds", map);
		return list;
	}

	@Override
	public int deleteByUserName(String userName) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userName", userName);
		int rows = getSqlMapClientTemplate().delete("TBL_OA_AUTH_USER.ibatorgenerated_deleteByUserName", map);
		return rows;
	}

	@Override
	public TblOaAuthUser selectByUserName(String userName) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userName", userName);
		List<TblOaAuthUser> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_USER.ibatorgenerated_selectByUserName", map);
		if (!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}
}